//index.js
//获取应用实例
const app = getApp()
let Axios = require('../../../common/js/ajax.js');
let Mtils = require('../../../common/js/Mtils.min.js');
Mtils = Mtils.Mtils
Page({
	data: {
		openid: '',
		shopName: '',
		shopAvatarUrl: '',
		curentNav: 2, //当前导航
		payType: 1,
		money: 0,
		tax: 0,
		bank_card: 0,
		bank_name: '',
		service_money: 0,
		store_id: 0,
		order_id: '',
		isIpx: app.globalData.isIpx ? true : false
	},
	//事件处理函数	
	onLoad: function(e) {
		this.setData({
			money: e.money,
			tax: e.ratio,
			bank_card: e.bank_card,
			bank_name: e.bank_name,
			service_money: e.service_money,
			store_id: e.id,
			order_id: e.order_id
		})
		var _this = this;
		this.uid = app.globalData.uid || ''
		this.Md5 = Mtils.security.hex_md5(this.uid) + app.globalData.secret;
		this.Md5 = Mtils.security.hex_md5(this.Md5);
		this.timesp = Mtils.now();
	},
	onReady: function() {
		wx.setNavigationBarTitle({
			title: '货款提取'
		})
	},
	handlePayTypeTap: function(e) {
		var id = e.currentTarget.dataset.id;
		this.setData({
			payType: id
		})
	},
	submit: function(e) {
		var _this = this;
		Axios.post(app.globalData.baseUrl + 'App/Capital/Cash/get_order_money', {
			uid: this.uid,
			time: this.timesp,
			sign: this.Md5,
			store_id: this.data.store_id,
			place: this.data.payType,
			order_id: this.data.order_id
		}, (res) => {
			console.log(res)
			if (res.status == 1) {
				var data = res.info
				if (_this.data.payType == 2) {
					wx.navigateTo({
						url: '/pages/drawing/progress/progress?ratio=' + this.data.tax + '&bank_card=' +
							this.data.bank_card + '&bank_name=' + this.data.bank_name + '&money=' + this.data.money +
							'&service_money=' + this.data.service_money + '&id=' + this.data.store_id
					})
				} else {
					wx.navigateTo({
						url: '/pages/drawing/success/success?ratio=' + this.data.tax + '&money=' + this.data.money +
							'&service_money=' + this.data.service_money + '&id=' + this.data.store_id
					})
				}

			} else {
				_this.showModal(res)
			}
		})
	},
	showModal: function(error) {
		wx.showModal({
			content: error.msg,
			showCancel: false,
		})
	}
})
